package org.liip.clickhouse.controller;

import lombok.extern.slf4j.Slf4j;

import org.liip.clickhouse.entity.User;
import org.liip.clickhouse.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.util.RandomUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/queryUser")
    public Object query(){
        List<?> userList = userMapper.queryUser();
        log.info(userList.toString());
        return userList.toString();
    }

    @RequestMapping("/insertUser")
    public Object insertUser(){
        User user = new User();
        user.setAppId("SS");
        user.setRegTime(new Date());
        user.setUserId(777744);
        user.setVersion("3.2");
        Integer flag = userMapper.insertUser(user);
        return flag;
    }
    
    @RequestMapping("/batchInsertUser")
    public Object batchInsertUser(){
    	List<User> userlst = new ArrayList<User>();
    	
        User user = new User();
        user.setAppId(RandomUtil.randomString(5));
        user.setRegTime(new Date());
        user.setUserId(RandomUtil.randomInt());
        user.setVersion("3.2");
        
        User user1 = new User();
        user1.setAppId(RandomUtil.randomString(5));
        user1.setRegTime(new Date());
        user1.setUserId(RandomUtil.randomInt());
        user1.setVersion("3.2");
        
        User user2 = new User();
        user2.setAppId(RandomUtil.randomString(5));
        user2.setRegTime(new Date());
        user2.setUserId(RandomUtil.randomInt());
        user2.setVersion("3.2");
        
        User user3 = new User();
        user3.setAppId(RandomUtil.randomString(5));
        user3.setRegTime(new Date());
        user3.setUserId(RandomUtil.randomInt());
        user3.setVersion("3.2");
        
        userlst.add(user);
        userlst.add(user1);
        userlst.add(user2);
        userlst.add(user3);
        
        Integer flag = userMapper.insertCollectList(userlst);
        return flag;
    }
}
